﻿using System;
using System.Drawing;
using System.Windows.Forms;
using PremierTaxFree.Properties;

namespace PremierTaxFree
{
    public partial class SplashScreen : Form
    {
        private readonly Timer m_Timer = new Timer();
        private bool fadeIn = true;
        private bool fadeOut = false;

        public SplashScreen()
        {
            InitializeComponent();
            StartTimer();
        }

        protected override void OnLoad(EventArgs e)
        {
            Color c = Resources.Internet.GetPixel(0, 0);
            Resources.Internet.MakeTransparent(c);
            this.panel1.BackgroundImage = Resources.Internet;
            this.FormBorderStyle = FormBorderStyle.None;
            this.Opacity = 1;
            base.OnLoad(e);
        }

        private void StartTimer()
        {
            m_Timer.Interval = 100;
            m_Timer.Tick += new EventHandler(Timer_Tick);
            m_Timer.Start();
        }

        private void Timer_Tick(object sender, EventArgs e)
        {
            if (fadeIn)
            {
                if (this.Opacity < 1.0)
                {
                    this.Opacity += 0.02;
                }
                else
                {
                    fadeIn = false;
                    fadeOut = true;
                }
            }
            else if (fadeOut) 
            {
                if (this.Opacity > 0)
                {
                    this.Opacity -= 0.02;
                }
                else
                {
                    fadeOut = false;
                }
            }

            if (!(fadeIn || fadeOut))
            {
                m_Timer.Stop();
                this.Close();
            }
        }
    }
}
